﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Common.Dto;
using Demo03.Domain;
using Demo03.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Demo03.Controller;

/// <summary>
/// 文章接口
/// </summary>
[ApiController]
[Route("article")]
[Authorize]
public class ArticleController
{
    private readonly ArticleService _articleService;

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="articleService"></param>
    public ArticleController(ArticleService articleService)
    {
        _articleService = articleService;
    }

    /// <summary>
    /// 查询全部
    /// </summary>
    /// <returns></returns>
    [HttpGet("find-all")]
    public Result<List<Article>> FindAll()
    {
        return Result.Success(_articleService.FindAll());
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="pageQuery">查询参数</param>
    /// <returns></returns>
    [HttpPost("find-paged-list")]
    public async Task<Result<PageObject<Article>>> FindPagedList([FromBody] PageQuery pageQuery)
    {
        var findPagedList = await _articleService.FindPagedList(pageQuery);
        return Result.Success(findPagedList);
    }
}